// import { login, logout, getInfo } from "@/api/user";
// import { getToken, setToken, removeToken } from "@/utils/auth";
// import { resetRouter } from "@/router";

const getDefaultState = () => {
  return {
    yywktoken: localStorage.getItem("yywktoken") || "",
    yywkusername: localStorage.getItem("yywkusername") || "",
    yywklastLogin: localStorage.getItem("yywklastLogin") || "",
    activetStatus: null,
  };
};

const state = getDefaultState();

const mutations = {
  RESET_STATE: (state, data) => {
    // Object.assign(state, getDefaultState());
    state.yywktoken = data.yywktoken;
    state.yywkusername = data.yywkusername;
    state.yywklastLogin = data.yywklastLogin;
  },
  SET_ACTIVETSTATUS: (state, data) => {
    // data.activeEnd = "";
    // data.activeAt = "";
    state.activetStatus = data;
  },
};

const actions = {
  // user login
  setLoginUserInfos({ commit }, userInfo) {
    console.log("login", userInfo);
    localStorage.setItem("yywktoken", userInfo.yywktoken);
    localStorage.setItem("yywkusername", userInfo.yywkusername);
    localStorage.setItem("yywklastLogin", userInfo.yywklastLogin);
    // const { username, password } = userInfo
    // return new Promise((resolve, reject) => {
    //   login({ username: username.trim(), password: password }).then(response => {
    //     const { data } = response
    commit("RESET_STATE", userInfo);
    //     setToken(data.token)
    //     resolve()
    //   }).catch(error => {
    //     reject(error)
    //   })
    // })
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
